package com.mobzilla.activity;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.mobzilla.model.ExperienceAnalysis;
import com.mobzilla.service.ServiceFactory;

public class ExperienceActivity  extends Activity
{
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);		
		setContentView(R.layout.exfactor);
		
		TextView tv = (TextView) findViewById(R.id.tvX);
		List<ExperienceAnalysis> analysis = ServiceFactory.getLoadBalancerInstance().getExperienceAnalysis();
		
		populateView(tv, analysis);
		
		Button backButton = (Button) findViewById(R.id.exBackButton);
		backButton.setOnClickListener(new MyBackButtonListener(this));
	}
	
	private void populateView(TextView tv, List<ExperienceAnalysis> analysis)
	{
		String ret = "Experience of developers on each component:\n\n";
		
		for(ExperienceAnalysis e : analysis)
		{
			ret = ret + e.toString();
		}
		
		tv.setText(ret);
	}
}

class MyBackButtonListener implements OnClickListener
{
	private Activity activity;
	
	public MyBackButtonListener(Activity a)
	{
		this.activity = a;
	}
	
	public void onClick(View v)
	{
		activity.finish();
	}
}
